﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Projekt
{
    public partial class stat : Form
    {
        Dalgen conn = Dalgen.Instance;
        public stat()
        {
            InitializeComponent();
            okButton.Enabled = false;
        }

        private void stat_Load(object sender, EventArgs e)
        {
            Firm supplier = new Firm();
            firmName.DataSource = supplier.getFirmList();
            firmName.DisplayMember = "CNev";
            firmName.ValueMember = "CegID";
        }

        private void year_Validating()
        {
            okButton.Enabled = true;
            try
            {
                Convert.ToInt64(yearInputBox.Text);
            }
            catch (Exception es) { okButton.Enabled = false; }
        }

        private void month_Validating()
        {
            okButton.Enabled = true;
            try
            {
                int honap = Convert.ToInt32(monthInputBox.Text);
                if (honap > 12 || honap <= 0) okButton.Enabled = false;
            }
            catch (Exception es) { okButton.Enabled = false; }
        }

        private void yearInputBox_TextChanged(object sender, EventArgs e)
        {
            year_Validating();
        }

        private void monthInputBox_TextChanged(object sender, EventArgs e)
        {
            month_Validating();
        }


        private void okButton_Click(object sender, EventArgs e)
        {
            double szum = 0;
            if (allSuplier.Checked == false)
            {
                szum = conn.vasarolCegtolStat(yearInputBox.Text, monthInputBox.Text, firmName.SelectedValue.ToString());
            }
            else
            {
                szum = conn.vasarol1HonapbaStat(yearInputBox.Text, monthInputBox.Text);
            }
            MessageBox.Show(szum.ToString());
        }
    }
}
